<?php

namespace app\shop\logic;

use app\shop\model\user\UserCommissionModel;
use think\Collection;
use think\facade\Db;

class UserCommissionLogic extends BaseLogic
{
    public function __construct()
    {
        $this->model = new UserCommissionModel();
    }

    public function LogList($params): Collection|array
    {
        $query = UserCommissionModel::getQuery();
        $where = [];
        $where[] = ['shop_user_id', '=', $params['user_id']];
        if (isset($params['status']) && $params['status']!='') {
            $where[] = ['status', '=', $params['status']];
        }
        $query->where($where);
        $this->buildEqualQuery($query, $params, [
        ]);

        $query->field([
            '*'
        ]);
        $query->order(['id' => 'desc']);
        $return = UserCommissionModel::paginateListQuery($query,true);
        if(isset($return['data'])){
            foreach ($return['data'] as $k=>$v){
                $return['data'][$k]['username'] = Db::name('shop_user')->where(['id'=>$v['shop_user_id']])->value('nickname');
            }
        }

        return $return;
    }


}